//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>

#include "ListBindingSitePredictionWeighted.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  String* filenamePatternsAA;
  String* filenamePatternsCH;
  String* filenamePatternsPH;
  String* filenamePatternsSS;
  String* filenamePatternsMT;
  
  String* filenameCATH;
  String* filenameAnchorResidues;
  String* filenameXMLModelsTrainingSet;
  String* scheme;

  String* filenameOut;

  if (argc < 9) {
    
    cout << "Error in the input parameters! Must by like: " << endl;
    cout << "./LocalizeBindingSiteByPatternsWeighted <Filename Patterns AA> ";
    cout <<                                         "<Filename Patterns CH> ";
    cout <<                                         "<Filename Patterns PH> ";
    cout <<                                         "<Filename Patterns SS> ";
    cout <<                                         "<Filename Patterns MT> ";
    cout <<                                         "<Filename CATH Profile> ";
    cout <<                                         "<Filename Anchor Residues> ";
    cout <<                                         "<Scheme> ";
    cout <<                                         "<Filename XML Models (Training Set)> ";
    cout <<                                         "<Filename Out>";
    cout << endl;
    
    return 0;
    
  }
  else {
    
    filenamePatternsAA           = new String(argv[1]);
    filenamePatternsCH           = new String(argv[2]);
    filenamePatternsPH           = new String(argv[3]);
    filenamePatternsSS           = new String(argv[4]);
    filenamePatternsMT           = new String(argv[5]);
    filenameCATH                 = new String(argv[6]);
    filenameAnchorResidues       = new String(argv[7]);
    scheme                       = new String(argv[8]);
    filenameXMLModelsTrainingSet = new String(argv[9]);
    filenameOut                  = new String(argv[10]);
    
    cout << "---------------------------------------------------------------------------------" << endl;
    cout << "                Filename Patterns AA : " << argv[1] << endl;
    cout << "                Filename Patterns CH : " << argv[2] << endl;
    cout << "                Filename Patterns PH : " << argv[3] << endl;
    cout << "                Filename Patterns SS : " << argv[4] << endl;
    cout << "                Filename Patterns MT : " << argv[5] << endl;
    cout << "               Filename CATH Profile : " << argv[6] << endl;
    cout << "            Filename Anchor Residues : " << argv[7] << endl;
    cout << "                              Scheme : " << argv[8] << endl;
    cout << "  Filename XML Models (Training Set) : " << argv[9] << endl;
    cout << "                        Filename Out : " << argv[10] << endl;
    cout << "---------------------------------------------------------------------------------" << endl;
    
  }
  
  ListBindingSitePredictionWeighted* listBindingSitePredictionWeighted = new ListBindingSitePredictionWeighted ();
  
  cout << "Preparing files..." << endl;
  listBindingSitePredictionWeighted->FilenameCATH(filenameCATH);
  listBindingSitePredictionWeighted->FilenameAnchorResidues(filenameAnchorResidues);
  listBindingSitePredictionWeighted->FilenameOut(filenameOut);
  
  listBindingSitePredictionWeighted->Scheme(scheme);
  listBindingSitePredictionWeighted->FilenameXMLModels(filenameXMLModelsTrainingSet);
  
  cout << "Loading data..." << endl;
  if (!listBindingSitePredictionWeighted->LoadData()) 
    cout << "Error loading data..." << endl;
  
  cout << "Getting anchor residues..." << endl;
  if (!listBindingSitePredictionWeighted->FillAnchorPositions())
    cout << "Error getting anchor residues..." << endl;
  
  cout << "Localizing the binding sites..." << endl;
  if (!listBindingSitePredictionWeighted->PredictBindingSiteWeighted(filenamePatternsAA, filenamePatternsCH, filenamePatternsPH, filenamePatternsSS, filenamePatternsMT, SCORE_NORMAL))
    cout << "Error localizing the binding sites..." << endl;

  cout << "Writing results..." << endl;
  if (!listBindingSitePredictionWeighted->OutToCSVFile())
    cout << "Error writing results..." << endl;
  
  cout << "Finished..." << endl << "Good Bye" << endl;
  
  if (listBindingSitePredictionWeighted) delete listBindingSitePredictionWeighted;
  if (filenamePatternsAA)                delete filenamePatternsAA;
  if (filenamePatternsCH)                delete filenamePatternsCH;
  if (filenamePatternsPH)                delete filenamePatternsPH;
  if (filenamePatternsSS)                delete filenamePatternsSS;
  if (filenamePatternsMT)                delete filenamePatternsMT;
  if (filenameCATH)                      delete filenameCATH;
  if (filenameAnchorResidues)            delete filenameAnchorResidues;
  if (filenameOut)                       delete filenameOut;

  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//


